Search code examples
javaswitch-statementcasezkzul

Switch and case attribute in ZK tag?


Here's an example:

<zk switch="${each}">

    <zk case="1">
        <hbox spacing="0">
            <textbox
                value="@bind(processChecklistBean.processCheckListDesc)" />
            <image
                src="/resource/image/greenbar-bar.gif" style="cursor:pointer"
                onClick="@command('showPickModalWindow',folderProcessObject = processChecklistBean)" />
        </hbox>
    </zk>
    <zk case="2">
        <hbox spacing="0">
            <textbox
                value="@bind(processChecklistBean.folderProcessChecklistRecord.checklistComment)" />

            <image
                src="/resource/image/greenbar-bar.gif" style="cursor:pointer"
                onClick="@command('showCommentPickDialog',folderProcessObject = processChecklistBean)">
            </image>
        </hbox>
    </zk>
                            </zk

Can anyone tell me :

  1. Why use this two attribute switch and case?

  2. In which case the switch and case attribute prefer ?


Solution

  • If You are aware of Java Switch Case you wilt easily understand why here this is used Just check this when-to-use-a-switch-statement-in-java

    Here if you will use if/else its bit complicated and it will check each condition while in Switch case loop will be automatically break. Like if case="1" satisfy current loop will break and it will not go forward and loop will again start this is a advantage