Monday, May 18, 2009

Different ways of using seam s:decorate and s:validate – Sample are based on Seamgen based applications.


 

1)    <s:decorate> without template attribute and with <s:validateAll>, requiredMessage, validateLength samples.

<s:decorate>

<s:validateAll>

<div class="prop">

<s:label id="editLabel" styleClass="#{invalid?'errors':''}">

created by

<s:span styleClass="required" rendered="true">*</s:span>

</s:label>

<span id="editSpan" class="#{invalid?'errors':''}">

invalid value > #{invalid}

<ice:inputText id="createdById" requiredMessage="This field value is required." partialSubmit="true" size="100" maxlength="130" value="#{userHome.instance.createdBy}">

<f:validateLength maximum="5" minimum="1" />

</ice:inputText>

</span>

<s:message styleClass="error errors" />

</div>

</s:validateAll>

</s:decorate>


 

Note: The reason being used s:decorate is that #{invalid} and #{required} are available inside s:decorate; #{required} evaluates to true if you have set the input component being decorated as required, and #{invalid} evaluates to true if a validation error occurs.


 


 

2)    <s:decorate> without template attribute and <s:validateAll>, validateLength and with only required="true" also work!!!.


 

<s:decorate>

<div class="prop">

<s:label id="editLabel" styleClass="#{invalid?'errors':''}">

created by

<s:span styleClass="required" rendered="true">*</s:span>

</s:label>

<span id="editSpan" class="#{invalid?'errors':''}">

invalid value > #{invalid}

<ice:inputText id="createdById" requiredMessage="This field value is required." partialSubmit="true" required="true" size="100" maxlength="130" value="#{featureSetHome.instance.createdBy}">

</ice:inputText>

</span>

<s:message styleClass="error errors" />

</div>

</s:decorate>


 


 

3)    With just <s:decorate>, required="true", s:message and without requiredMessage attribute.

<s:decorate>

<div class="prop">

<s:label id="editLabel" styleClass="#{invalid?'errors':''}">

created by

<s:span styleClass="required" rendered="true">*</s:span>

</s:label>

<span id="editSpan" class="#{invalid?'errors':''}">

invalid value > #{invalid}

<ice:inputText id="createdById" partialSubmit="true" required="true" size="100" maxlength="130" value="#{featureSetHome.instance.createdBy}">

</ice:inputText>

</span>

<s:message styleClass="error errors" />

</div>

</s:decorate>

Wednesday, May 6, 2009

Integration ICEfaces message and Seam’s FacesMessages

How to display error/confirmation message wherever you want

  1. – Without JSF UI control's Id and help of ice:messge's id attribute

In Backing bean -

  1. import org.jboss.seam.faces.FacesMessages;
  2. @In private FacesMessages facesMessages;
  3. facesMessages.addToControl("msgId", "Saved successfully!!!");

In JSF/Facelets page –

Put the following code wherever you want the error to be displayed -

<ice:message
id="msgId" for="msgId"
/>

  1. With make use of JSF UI control's Id

In Backing bean -

  1. import org.jboss.seam.faces.FacesMessages;
  2. @In private FacesMessages facesMessages;
  3. facesMessages.addToControl("jsfUIComponentId", "You have error message in the first name");

In JSF/Facelets page –

Put the following code wherever you want the error to be displayed -

<ice:outputText
id="jsfUIComponentId"
value="First Name"
/>

<br/>

<br/>

<!-- without id attribute since we added in outputText UI component -->

<ice:message
for="jsfUIComponentId"
/>

Note: To use facesMessages.addToControl("someJSF_UIComponentId", "some msg") - we need some UI component with Id's values with the same value which we used in the backing bean.

Using constants in facelets or JSF

http://swexplorations.blogspot.com/2008/09/using-constants-in-facelets.html

Says

The idea here is to use a backing bean implementing 'Map' interface and implementing its 'get' method to return appropriate value for the given constant. This is achieved by using introspection.

Here is the snippet of xhtml that uses constants defined in backing beans, use of constants is highlighted using red color:


<rich:tabPanel switchType="ajax" id="tabPanel1"
selectedTab="#{bean.selectedTab}">
<rich:tab label="First" rendered="true" name="first">
<h:outputText value="First Test component" />
</rich:tab>
<rich:tab label="Second" rendered="true" name="second">
<h:outputText value="Second Test component" />
</rich:tab>
</rich:tabPanel>
<a4j:commandLink reRender="tabPanel1" action="#{bean.changeSelectedTab}"
value="first">
<f:setPropertyActionListener
value="#{
StaticAccessor['demo.Bean.FIRST_TAB']}"
target="#{bean.selectedTabInt}" />
</a4j:commandLink>
<rich:spacer width="10"></rich:spacer>
<a4j:commandLink reRender="tabPanel1" action="#{bean.changeSelectedTab}"
value="second">
<f:setPropertyActionListener
value="#{
StaticAccessor['demo.Bean.SECOND_TAB']}"
target="#{bean.selectedTabInt}" />
</a4j:commandLink>


Here is the backing bean implementation that provides map interface (only get implementation is shown here):


public class StaticAccessor implements Map{

public Object get(Object arg0) {
if ((arg0 != null) && (arg0 instanceof String)) {
String input = (String) arg0;
int index = input.lastIndexOf('.');
if (index == -1) {
return null;
}
String className = input.substring(0, index);
String constant = input.substring(index + 1);
try {
Class forName = Class.forName(className);
Field declaredField = forName.getDeclaredField(constant);
int value = declaredField.getInt(forName);
return value;
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}

Posted by Atul Kshirsagar


 

Scriptless JSP Pages: The Constant Constants Consternation

http://www.javaranch.com/journal/200601/ccc.html

Advanced Facelets programming

http://www.ibm.com/developerworks/web/library/j-facelets2.html

Monday, May 4, 2009

Difference between setOrder and setOrderColumn in Seam

Difference between setOrder and setOrderColumn in Seam


 

  1. This code work fine.

programList.setOrder("program.programName asc, program.programId desc");

  1. The below code snippet won't work –
    1. programList.setOrderColumn("program.programName asc, program.programId desc");
    2. programList.setOrderColumn("program.programName asc);

      It throws the following exceptions - Caused by java.lang.IllegalArgumentException with message: "invalid order column ("program.programName asc, program.programId desc" must match the regular expression "^\w+(\.\w+)*$")"

    3. This works fine - programList.setOrderColumn("program.programName");
      1. But we have to set

        customerList.setOrderDirection("asc"); or customerList.setOrderDirection("desc");

Saturday, December 8, 2007

first blog

Hi,

this is my first blog....