Erster Versuch, ein Tag Label in Widgets zu integrieren.

git-svn-id: https://svn.libreccm.org/ccm/trunk@2391 8810af33-2d31-482b-a856-94f89814c4df
master
pb 2013-10-28 08:31:25 +00:00
parent fd1f651621
commit e917176d17
4 changed files with 50 additions and 16 deletions

View File

@ -360,9 +360,13 @@ public class Label extends BlockStylable implements Cloneable {
label.addAttribute("escape", "no"); label.addAttribute("escape", "no");
} }
String key = getGlobalizedMessage().getKey().substring(getGlobalizedMessage().getKey().lastIndexOf(".") + 1); String key = getGlobalizedMessage()
.getKey()
.substring(getGlobalizedMessage()
.getKey().lastIndexOf(".") + 1);
// This if clause is needed to prevent printing of keys if the GlobalizedMessage was created from a String by this class // This if clause is needed to prevent printing of keys if the
// GlobalizedMessage was created from a String by this class
if(!key.equals(target.getLabel(state))) { if(!key.equals(target.getLabel(state))) {
label.addAttribute("key", key); label.addAttribute("key", key);
} }

View File

@ -171,7 +171,7 @@ public class TextArea extends Widget implements BebopConstants {
} }
/** /**
* Generates the DOM for the textarea widget * Generates the DOM for the textarea widget.
* <p>Generates DOM fragment: * <p>Generates DOM fragment:
* <p><code>&lt;bebop:textarea name=... value=... [onXXX=...]/> * <p><code>&lt;bebop:textarea name=... value=... [onXXX=...]/>
* </code> * </code>
@ -180,6 +180,9 @@ public class TextArea extends Widget implements BebopConstants {
Element textarea = parent.newChildElement(getElementTag(), BEBOP_XML_NS); Element textarea = parent.newChildElement(getElementTag(), BEBOP_XML_NS);
textarea.addAttribute("name", getName()); textarea.addAttribute("name", getName());
if (getLabel() != null)
textarea.addAttribute("label",
(String)getLabel().localize(state.getRequest()));
ParameterData pData = getParameterData(state); ParameterData pData = getParameterData(state);
if( null != pData ) { if( null != pData ) {

View File

@ -80,6 +80,8 @@ public abstract class Widget extends BlockStylable implements Cloneable,
private ParameterListener m_forwardParameter = null; private ParameterListener m_forwardParameter = null;
private PrintListener m_printListener; private PrintListener m_printListener;
private Form m_form; private Form m_form;
/** The optional (localized) label (or title) of this widget. */
private GlobalizedMessage m_label;
private ValidationGuard m_guard = null; private ValidationGuard m_guard = null;
@ -392,6 +394,20 @@ public abstract class Widget extends BlockStylable implements Cloneable,
setAttribute("hint", (String)hint.localize() ); setAttribute("hint", (String)hint.localize() );
} }
/**
* Sets a Label for the widget.
*/
public void setLabel(GlobalizedMessage label) {
m_label = label;
}
/**
* Sets a Label for the widget.
*/
public GlobalizedMessage getLabel() {
return m_label;
}
/** /**
* Gets the default value in the parameter model for this element. * Gets the default value in the parameter model for this element.
@ -521,7 +537,7 @@ public abstract class Widget extends BlockStylable implements Cloneable,
} }
/** /**
* Generates the DOM for the given widget * Generates the DOM for the given widget.
* <p>Generates DOM fragment: * <p>Generates DOM fragment:
* <p><code>&lt;bebop:formWidget name=... type=... value=... [onXXX=...]> * <p><code>&lt;bebop:formWidget name=... type=... value=... [onXXX=...]>
* &lt;/bebop:formWidget></code> */ * &lt;/bebop:formWidget></code> */
@ -530,6 +546,9 @@ public abstract class Widget extends BlockStylable implements Cloneable,
widget.addAttribute("type", getType()); widget.addAttribute("type", getType());
widget.addAttribute("name", getName()); widget.addAttribute("name", getName());
if (m_label != null)
widget.addAttribute("label",
(String)m_label.localize(state.getRequest()));
exportAttributes(widget); exportAttributes(widget);
String value = null; String value = null;
ParameterData p = getParameterData(state); ParameterData p = getParameterData(state);
@ -553,9 +572,9 @@ public abstract class Widget extends BlockStylable implements Cloneable,
while (i.hasNext()) { while (i.hasNext()) {
Element errors = parent.newChildElement(BEBOP_FORMERRORS, BEBOP_XML_NS); Element errors = parent.newChildElement(BEBOP_FORMERRORS, BEBOP_XML_NS);
errors.addAttribute( errors.addAttribute("message",
"message", (String) ((GlobalizedMessage)
(String) ((GlobalizedMessage) i.next()).localize(state.getRequest()) i.next()).localize(state.getRequest())
); );
errors.addAttribute("id", getName()); errors.addAttribute("id", getName());
} }
@ -656,10 +675,12 @@ public abstract class Widget extends BlockStylable implements Cloneable,
* *
* @pre state != null * @pre state != null
*/ */
@Override
public void respond(PageState state) throws javax.servlet.ServletException { public void respond(PageState state) throws javax.servlet.ServletException {
getForm().respond(state); getForm().respond(state);
} }
@Override
public Object clone() throws CloneNotSupportedException { public Object clone() throws CloneNotSupportedException {
Widget cloned = (Widget) super.clone(); Widget cloned = (Widget) super.clone();
cloned.setForm(null); cloned.setForm(null);
@ -705,6 +726,7 @@ public abstract class Widget extends BlockStylable implements Cloneable,
getParameterData(PageState.getPageState()).addError(error); getParameterData(PageState.getPageState()).addError(error);
} }
@Override
public String toString() { public String toString() {
return super.toString() + " [" + getName() + "]"; return super.toString() + " [" + getName() + "]";
} }

View File

@ -130,25 +130,30 @@ public class SetupView extends Form
m_saveCancel.getSaveButton().setButtonLabel(GlobalizationUtil.gz( m_saveCancel.getSaveButton().setButtonLabel(GlobalizationUtil.gz(
"forum.ui.settings.save")); "forum.ui.settings.save"));
// //////////////////////////////////////////////////////////////////// // preliminary step 4: Create Introductory text area
// Create the pane
// ////////////////////////////////////////////////////////////////////
/* Introductory text fiel */
m_introduction = new TextArea("introduction", 8, 60, TextArea.SOFT); m_introduction = new TextArea("introduction", 8, 60, TextArea.SOFT);
m_introduction.addValidationListener( m_introduction.addValidationListener(
new StringInRangeValidationListener(0, 4000, new StringInRangeValidationListener(0, 4000,
GlobalizationUtil.gz( GlobalizationUtil.gz(
"forum.ui.validation.introduction_too_long") "forum.ui.validation.introduction_too_long")
)); ));
m_introduction.setMetaDataAttribute("label", (String) GlobalizationUtil.gz( // m_introduction.setMetaDataAttribute("label", (String) GlobalizationUtil.gz(
"forum.ui.settings.introduction").localize()); // "forum.ui.settings.introduction").localize());
m_introduction.setLabel(GlobalizationUtil.gz(
"forum.ui.settings.introduction"));
// preliminary step 5: Create title text field
m_title = new TextField("title"); m_title = new TextField("title");
m_title.setMetaDataAttribute("label", (String) GlobalizationUtil.gz( // m_title.setMetaDataAttribute("label", (String) GlobalizationUtil.gz(
"forum.ui.settings.title").localize()); // "forum.ui.settings.title").localize());
m_title.setLabel(GlobalizationUtil.gz(
"forum.ui.settings.title"));
m_title.setSize(70); m_title.setSize(70);
// ////////////////////////////////////////////////////////////////////
// Create the pane
// ////////////////////////////////////////////////////////////////////
add(m_title); add(m_title);
add(m_introduction); add(m_introduction);
add(m_settings); add(m_settings);