0

reduce my code

asked 2010-03-29 09:15:27 +0800

saad gravatar image saad
207 1 2

hi all
i have my page loggin zul:

<?xml version="1.0" encoding="UTF-8"?>
<?page title="MyFirstZKProject" style="text-align:center;"?>
<p:zk xmlns:p="http://www.zkoss.org/2005/zul">
<!-- ROOT ELEMENT -->
<p:window title="Omnidata" width="100%" height="768px"
style=" background: #EDF7F2; border: 4px groove #003366; text-align: center;"
id="logWin" use="com.action.Login"
xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:p="http://www.zkoss.org/2005/zul"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">

<!-- CSS -->
<p:style src="/css/main.css" dynamic="true"/>
<p:div align="center">
<p:vbox spacing="2em" width="500px" style="text-align: center;">
<!-- IMAGE -->
<p:div align="center">
<p:image style="border: 3px groove #000066;" src="/page/img/omnidata.JPG"/>
</p:div>
<!-- Window LOGIN -->
<p:window title="Login" width="500px" id="loginDlg" onOK="login()" sclass="windowStyle" context="ActionPopup">
<p:div align="center">
<!-- TIMER -->
<p:label id="lheure" style="text-align: right;font-size: small;font-weight: bold;color: #cc3333;"/>
<p:timer id="timer" delay="1000" repeats="true" onTimer="lheure.setValue(new Date().toGMTString())"/>
<!-- SEPARATOR -->
<p:separator/>
<p:separator/>
<p:separator/>
<!-- GRID -->
<p:grid width="350px">
<p:columns>
<p:column width="30px"/>
<p:column width="60px"/>
<p:column width="120px"/>
</p:columns>
<p:rows>
<p:row>
<p:image src="/page/img/login.JPG"/>
<p:label value="Login"/>
<p:textbox zclass="mydb" id="userName" width="120px" sclass="windowStyle"/>
</p:row>
<p:row >
<p:image src="/page/img/paswor.JPG"/>
<p:label value="Password"/>
<p:textbox id="password" type="password" width="120px" sclass="windowStyle"/>
</p:row>
</p:rows>
</p:grid>
<!-- SEPARATOR -->
<p:separator/>
<p:separator/>
<!-- BUTTON -->
<p:div style="text-align: center;">
<p:button label="Se connecter" onClick="login()"/>
</p:div>
<!-- SEPARATOR -->
<p:separator/>
<p:separator/>
<p:div align="center">
<p:image style="border: 1px groove #000066;" src="/page/img/itarone.jpg"/>
</p:div>
<!-- SEPARATOR -->
<p:separator/>
<p:separator/>
<p:zscript> <![CDATA[ userName.focus(); ]]></p:zscript>
</p:div>
</p:window>
<!-- MENU POPUP -->
<p:menupopup id="ActionPopup">
<p:menuitem label="Overlap" onClick="loginDlg.doOverlapped();"/>
<p:menuitem label="Release" onClick="loginDlg.doEmbedded();"/>
</p:menupopup>
</p:vbox>
</p:div>
<!-- ZSCRIPT -->
<p:zscript>
<![CDATA[
void login()
{
/* parameter */
password = logWin.getFellow("loginDlg").getFellow("password");
userName = logWin.getFellow("loginDlg").getFellow("userName");
emptyConstraint = SimpleConstraint.getInstance("no empty");
password.setConstraint(emptyConstraint);
userName.setConstraint(emptyConstraint);

/* we run getValue to validate */
password.getValue();
userName.getValue();

/* we run function from com.action.Login.java */
logWin.login(userName, password);
Executions.sendRedirect("/page/role.zul");
}
/* we remove "user" from session */
sessionScope.remove("user");
]]>
</p:zscript>
</p:window>
</p:zk>

and i want reduce the code by facotorizing it
please can you suggeste me way so i can minimize the nombre of lines of codes
so my zul can be light on lines of code
thx for help

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2010-03-29 10:31:45 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

I can't suggest anything because it's unreadable...if you surround code fragments with [ c o d e ] and [ / c o d e] without the spaces, it will show your code formatted...

link publish delete flag offensive edit

answered 2010-03-29 10:47:26 +0800

Arsen gravatar image Arsen
381 2

And why do you want to reduce the code? For me it does not seem huge or too complicated. Only may be you can remove p:. But that's all.

link publish delete flag offensive edit

answered 2010-03-30 03:38:52 +0800

saad gravatar image saad
207 1 2

hi
cos when i compare with a login page doing by jsp i find only 24 lines
and here with zk i have 100 lines
so make the comparaition and seeeeee
thx for again

link publish delete flag offensive edit

answered 2010-03-30 04:53:27 +0800

TOtte gravatar image TOtte
93 2

there is almost no real code that could be reduced. You have 11 lines of code, the rest is layout.

link publish delete flag offensive edit

answered 2010-03-30 06:42:43 +0800

saad gravatar image saad
207 1 2

nice answer
so how i can reduce the nomber of lines code of my layout as possible
so the other developper will find that easy to read
thx

link publish delete flag offensive edit

answered 2010-03-31 01:52:38 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

You can use include component to separate them.

link publish delete flag offensive edit

answered 2010-03-31 03:48:07 +0800

saad gravatar image saad
207 1 2

thx for all help

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-03-29 09:15:27 +0800

Seen: 599 times

Last updated: Mar 31 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More