• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1927
  • Last Modified:

Struts related Questions

2 Struts related Q's :-)

(1)

<TD colspan="3" >
<html:radio property="displayPeriod" value="days"> Days </html:radio>
<html:radio property="displayPeriod" value="months"> Months </html:radio>
<html:radio property="displayPeriod" value="years"> Years </html:radio>
</TD>

In the above struts - tags, how can i make "Days" to be checked by default. I tried setting
String displayPeriod = "days"; in my ActionForm, but it didnt worked.

(2)

<logic:iterate name="DateRange" id="Date">
          <td class="tdHeader"> <bean:write name="Date" property="label" /> </td>
</logic:iterate>

In the above, "DateRange" is a set of dates that are displayed in the <td>. Now, if the date is a weekend, i want a different *CLASS* for td.

i.e.

if(Date != weekend)
    <td class="tdNormal"> <bean:write name="Date" property="label" /> </td>
else
    <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>

Thanks.
0
ldbkutty
Asked:
ldbkutty
  • 11
  • 7
  • 3
  • +1
4 Solutions
 
zzynxSoftware engineerCommented:
Struts Tip #16 - How to (not) check a radio button :
http://www.jguru.com/faq/view.jsp?EID=1028442
0
 
girionisCommented:
> In the above, "DateRange" is a set of dates that are displayed in the
> <td>. Now, if the date is a weekend, i want a different *CLASS* for td.

> i.e.

> if(Date != weekend)
>     <td class="tdNormal"> <bean:write name="Date" property="label" /> </td>
> else
>     <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>

> Thanks.


What type if the "Date"? If it is string you might as well do:

if(Date.equals("Saturday") || Date.equals("Sunday"))
    <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
else
    <td class="tdNormal"> <bean:write name="Date" property="label" /> </td>
0
 
girionisCommented:
Ah... is is a java.util.Date? You could do:

GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
if (dayOfWeek == 1 || dayOfWeek == 7) // 1 is sunday 7 is saturday
{
    <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
}
else
    <td class="tdNormal"> <bean:write name="Date" property="label" /> </td>
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
suprapto45Commented:
Hello,

1. Well, if you want to check the radio button by default, you have to set it from the ActionForm that you run before the .jsp is loaded. However, you must ensure that displayPeriod is in the right form. I think that you should have the <html:form action=blah.do>

<TD colspan="3" >
<html:radio property="displayPeriod" value="days"> Days </html:radio>
<html:radio property="displayPeriod" value="months"> Months </html:radio>
<html:radio property="displayPeriod" value="years"> Years </html:radio>
</TD>

In the ActionForm, you have to set like this:
// Java codes here
yourForm.setDisplayPeriod("days");



0
 
suprapto45Commented:
For the second question, you can either use JSTL tag or <logic:equal>

<logic:equal name="Date" value="whatYouWant (Saturday or Sunday)">
    <td class="tdNormal"> <bean:write name="Date" property="label" /> </td>
</logic:equal>

<logic:notEqual name="Date"  value="whatYouWant (Saturday or Sunday)">
    <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
</logic:notEqual>

Well, I hope that helps you
0
 
ldbkuttyAuthor Commented:
sorry, my weekend took a long time...

is it possible to use more than one value check in <logic:equal ...> tag. something like:

<logic:notEqual name="Date"  value="1 || 2">
    <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
</logic:notEqual>

i heard its not possible. Is it so or any other alternatives ?
0
 
girionisCommented:
Not sure if it is possible but you can use the jstl (http://www.javaworld.com/javaworld/jw-02-2003/jw-0228-jstl.html) and do something like:

<c:if test ${Date == 1 OR Date == 2}><td class="tdWeekend"> <bean:write name="Date" property="label" /> </td></c:if>
0
 
ldbkuttyAuthor Commented:
girinois,

After deploying JSTL, i am getting:

Unable to load tag handler class "org.apache.taglibs.standard.tag.rt.core.WhenTag" for tag "c:when"

( i tried with <c:choose><c:when>...</c:when><c:otherwise>...</c:otherwise></c:choose> )

but i do have that WhenTag class in my "standard.jar" file and i included it in the 'lib' folder.

Any ideas ?
0
 
ldbkuttyAuthor Commented:
actually, i am not able to include any tags.

<c:if> throws:

Unable to load tag handler class "org.apache.taglibs.standard.tag.rt.core.IfTag" for tag "c:if"

but my eclipse editor successfully showed me all the tags.
0
 
girionisCommented:
Ehm.. I am not sure what's going on, you probably have misconfigured the JSTL. Have you followed the instructions in the link I posted?
0
 
ldbkuttyAuthor Commented:
alrite, i managed it,...but :

<logic:iterate name="DateRange" id="Date">
                <c:choose>
                      <c:when test='${Date == "1" || Date == "7"}'>
                            hai
                      </c:when>
                      <c:otherwise>
                            hallo
                      </c:otherwise>
                </c:choose>
</logic:iterate>

always gives me the output:  hallo

what should i give exactly in the "test" ?

I need to generate the <c:when ...> for this:

<logic:equal name="Date" property="dayOfWeek" value="1">
                      <td id="weekends" class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
                </logic:equal>
                <logic:notEqual name="Date" property="dayOfWeek" value="1">
                      <td class="tdHeader"> <bean:write name="Date" property="label" /> </td>
                </logic:notEqual>

Thanks.
0
 
girionisCommented:
Try this:

 Comment from zzynx
Date: 09/03/2004 03:12PM GMT
ID: 11973552
 Comment  


Struts Tip #16 - How to (not) check a radio button :
http://www.jguru.com/faq/view.jsp?EID=1028442
 
Comment from girionis
Date: 09/03/2004 04:01PM GMT
ID: 11974176
 Your Comment  


> In the above, "DateRange" is a set of dates that are displayed in the
> <td>. Now, if the date is a weekend, i want a different *CLASS* for td.

> i.e.

> if(Date != weekend)
>     <td class="tdNormal"> <bean:write name="Date" property="label" /> </td>
> else
>     <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>

> Thanks.


What type if the "Date"? If it is string you might as well do:

if(Date.equals("Saturday") || Date.equals("Sunday"))
    <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
else
    <td class="tdNormal"> <bean:write name="Date" property="label" /> </td>

 
Comment from girionis
Date: 09/03/2004 04:08PM GMT
ID: 11974257
 Your Comment  


Ah... is is a java.util.Date? You could do:

GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
if (dayOfWeek == 1 || dayOfWeek == 7) // 1 is sunday 7 is saturday
{
    <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
}
else
    <td class="tdNormal"> <bean:write name="Date" property="label" /> </td>

 
Comment from suprapto45
Date: 09/03/2004 04:40PM GMT
ID: 11974583
 Comment  


Hello,

1. Well, if you want to check the radio button by default, you have to set it from the ActionForm that you run before the .jsp is loaded. However, you must ensure that displayPeriod is in the right form. I think that you should have the <html:form action=blah.do>

<TD colspan="3" >
<html:radio property="displayPeriod" value="days"> Days </html:radio>
<html:radio property="displayPeriod" value="months"> Months </html:radio>
<html:radio property="displayPeriod" value="years"> Years </html:radio>
</TD>

In the ActionForm, you have to set like this:
// Java codes here
yourForm.setDisplayPeriod("days");




 
Comment from suprapto45
Date: 09/03/2004 04:45PM GMT
ID: 11974644
 Comment  


For the second question, you can either use JSTL tag or <logic:equal>

<logic:equal name="Date" value="whatYouWant (Saturday or Sunday)">
    <td class="tdNormal"> <bean:write name="Date" property="label" /> </td>
</logic:equal>

<logic:notEqual name="Date"  value="whatYouWant (Saturday or Sunday)">
    <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
</logic:notEqual>

Well, I hope that helps you
 
Comment from ldbkutty
Date: 09/06/2004 10:37PM GMT
ID: 11992772
 Author Comment  


sorry, my weekend took a long time...

is it possible to use more than one value check in <logic:equal ...> tag. something like:

<logic:notEqual name="Date"  value="1 || 2">
    <td class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
</logic:notEqual>

i heard its not possible. Is it so or any other alternatives ?
 
Comment from girionis
Date: 09/07/2004 06:44AM GMT
ID: 11994199
 Your Comment  


Not sure if it is possible but you can use the jstl (http://www.javaworld.com/javaworld/jw-02-2003/jw-0228-jstl.html) and do something like:

<c:if test ${Date == 1 OR Date == 2}><td class="tdWeekend"> <bean:write name="Date" property="label" /> </td></c:if>
 
Comment from ldbkutty
Date: 09/07/2004 09:45AM GMT
ID: 11995052
 Author Comment  


girinois,

After deploying JSTL, i am getting:

Unable to load tag handler class "org.apache.taglibs.standard.tag.rt.core.WhenTag" for tag "c:when"

( i tried with <c:choose><c:when>...</c:when><c:otherwise>...</c:otherwise></c:choose> )

but i do have that WhenTag class in my "standard.jar" file and i included it in the 'lib' folder.

Any ideas ?
 
Comment from ldbkutty
Date: 09/07/2004 09:47AM GMT
ID: 11995060
 Author Comment  


actually, i am not able to include any tags.

<c:if> throws:

Unable to load tag handler class "org.apache.taglibs.standard.tag.rt.core.IfTag" for tag "c:if"

but my eclipse editor successfully showed me all the tags.
 
Comment from girionis
Date: 09/07/2004 10:17AM GMT
ID: 11995188
 Your Comment  


Ehm.. I am not sure what's going on, you probably have misconfigured the JSTL. Have you followed the instructions in the link I posted?
 
Comment from ldbkutty
Date: 09/07/2004 10:33AM GMT
ID: 11995258
 Author Comment  


alrite, i managed it,...but :

<logic:iterate name="DateRange" id="Date">
               <c:choose>
                    <c:when test='${Date == 1 || Date == 7}'>
                         hai
                    </c:when>
                    <c:otherwise>
                         hallo
                    </c:otherwise>
               </c:choose>
</logic:iterate>
 
 What type is "Date"?
0
 
girionisCommented:
Bah.. sorry it seems that I accidentaly copies/pasted the whole page :(

Try this one:

<logic:iterate name="DateRange" id="Date">
               <c:choose>
                    <c:when test='${Date == 1 || Date == 7}'>
                         hai
                    </c:when>
                    <c:otherwise>
                         hallo
                    </c:otherwise>
               </c:choose>
</logic:iterate>
 
 What type is "Date"?
0
 
ldbkuttyAuthor Commented:
This is my current "struts" tags that is working for one day (sunday):

 <logic:iterate name="DateRange" id="Date">
                <logic:equal name="Date" property="dayOfWeek" value="1">
                      <td id="weekends" class="tdWeekend"> <bean:write name="Date" property="label" /> </td>
                </logic:equal>
                <logic:notEqual name="Date" property="dayOfWeek" value="1">
                      <td class="tdHeader"> <bean:write name="Date" property="label" /> </td>
                </logic:notEqual>
 </logic:iterate>
 
Date is just an "id" for the procedding loop. ( ? )

"DateRange" is the Attribute set in my Action Class as:

request.setAttribute("DateRange", periodSession.getPeriodByDateRange(dateFrom, dateTo));

and getPeriodByDateRange() in my PeriodSession Class returns it as PeriodView[] (View Object).

So, in my PeriodView Class i have :

public final static int SUNDAY = 1;
public final static int MONDAY = 2;
public final static int TUESDAY = 3;
public final static int WEDNESDAY = 4;
public final static int THURSDAY = 5;
public final static int FRIDAY = 6;
public final static int SATURDAY = 7;
      
private String label;
private Date dateFrom;
private Date dateTo;
private int dayOfWeek;

/**
 * Return true if the day is a weekend day
 *  
 * @return boolean
 */
public boolean getIsWeekEndDay(){
      if(dayOfWeek == SUNDAY || dayOfWeek == SATURDAY)
            return true;
      
      return false;
}

/**
 * @return Returns the dayOfWeek.
 */
public int getDayOfWeek() {
      return dayOfWeek;
}
/**
 * @param dayOfWeek The dayOfWeek to set.
 */
public void setDayOfWeek(int dayOfWeek) {
      this.dayOfWeek = dayOfWeek;
}

and so on.
0
 
ldbkuttyAuthor Commented:
Date is : java.util.Date
0
 
girionisCommented:
Then do:

<logic:iterate name="DateRange" id="Date">
               <c:choose>
                    <c:when test='${Date.dayOfWeek == 1 || Date.dayOfWeek == 7}'>
                         hai
                    </c:when>
                    <c:otherwise>
                         hallo
                    </c:otherwise>
               </c:choose>
</logic:iterate>
0
 
girionisCommented:
Hmm.. If it is priovate it won't work :(
0
 
girionisCommented:
Basically you access the properites by using the . and then the property name of the class, but thwy have to be public.
0
 
girionisCommented:
On second thought, try it and it might work. I don't remember how exactly it works, it might be through the accessor and mutators that the member variables are exposed.
0
 
ldbkuttyAuthor Commented:
Ahhh.....everything worked fine after i include:

<%@ page isELIgnored="false"%>

in my JSP. Thanks to all for participating. I will split the points.
0
 
zzynxSoftware engineerCommented:
Thanks ldbkutty :)
0
 
girionisCommented:
:)
0
 
suprapto45Commented:
thank you very much. I am sorry that I cannot participate on last message because I am busy working. Anyway, thanks for the points
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 11
  • 7
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now