tags:

views:

36

answers:

2

I'm trying to filter a listPage by date and userid. From a datatable the selected userid and date value is passed to the listPage with the f:param tag. The list page shows an error that says "value must be a date" and the filter doesnt work. It works if its just filtered by userid without the date. What could I be doing wrong? or How can I get this to work? I've also tried using the JBoss seam date converter that doesnt work too.

Heres my code:

firstPage.xhtml

<h:column>
    <f:facet name="header">Date</f:facet>
            <h:outputText value="#{_auditEventFact[3]}">
            </h:outputText>
</h:column>



    <rich:column styleClass="action">
        <f:facet name="header">Action</f:facet>  
    <s:link value="View" view="/AuditEventFactList.xhtml" action="# auditEventFactList.lookUpUserAuditRecords()}">
    <f:param name="userid" value="#{_auditEventFact[1]}"/>
    <f:param name="ntimestamp" value="#{_auditEventFact[3]}"/>
  </s:link>                                             
    </rich:column>

pages.xml

<param name="from"/>
   <param name="userid" value="#{auditEventFactList.auditEventFact.userid}"/>
   <param name="ntimestamp" value="#{auditEventFactList.auditEventFact.ntimestamp}" converterId="javax.faces.DateTime"/>

ListAction.java

private static final String EJBQL = "select auditEventFact from AuditEventFact auditEventFact";
private static final String[] RESTRICTIONS = {
        "lower(auditEventFact.userid) like concat(lower(#{auditEventFactList.auditEventFact.userid}),'%')",
        "auditEventFact.ntimestamp = #{auditEventFactList.auditEventFact.ntimestamp}",
        "lower(auditEventFact.auditid) like concat(lower(#{auditEventFactList.auditEventFact.auditid}),'%')", };

private AuditEventFact auditEventFact = new AuditEventFact();   
public AuditEventFactList() {
    setEjbql(EJBQL);
    setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
    setMaxResults(25);
}

EntityBean.java

   @Temporal(TemporalType.TIMESTAMP)
    @Column(name="NTIMESTAMP#", length=11)
    public Date getNtimestamp() {
        return this.ntimestamp1;
    }

    public void setNtimestamp(Date ntimestamp1) {
        this.ntimestamp1 = ntimestamp1;
    }
A: 

I don't do Seam, so I can't give a Seam-targeted answer. But basically, the f:param sets a HTTP request parameter which can contain only strings since they are transferred in ASCII flavor as per the HTTP specification. It isn't been passed as a fullworthy java.util.Date object as you seem to expect. Instead, the outcome of String.valueOf(date) is been passed. Its format is specified in Date#toString().

In plain JSF terms, there are two solutions:

  1. Use <h:commandLink> instead in combination with f:setPropertyActionListener it is capable of "passing" fullworthy non-standard Java objects as "parameters".

    <h:commandLink value="View" action="#{auditEventFactList.lookUpUserAuditRecords}">
        <f:setPropertyActionListener target="#{entityBean.ntimestamp}" value="#{_auditEventFact[3]}"/>
    </h:commandLink>
    
  2. Use String instead of Date in ntimestamp or wrap another String setter around it which converts the String to Date and delegates to the original Date setter. The java.text.SimpleDateFormat may be helpful in this.

See if this is doable in combination with Seam.

BalusC
A: 

Can you use the <s:convertDateTime /> tag on a parameter? I've never tried it myself, but it's worth looking in to.

Shadowman