Xamarin.iOS Custom View with class file VS2019 Version 16.9 - xamarin.ios

Can anyone please guide me how to create a custom view in Xamarin.iOS using XCode.
Im trying to create a Custom Circular View with the class file. I was able to create a XIB file but not able to create a class file.

To continue on what you did, do the following.
Create an empty class and name it CircularView
public partial class CircularView : UIView
{
public static readonly NSString Key = new NSString("CircularView");
public static readonly UINib Nib;
static CircularView()
{
Nib = UINib.FromName("CircularView", NSBundle.MainBundle);
}
protected CircularView(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}
public static CircularView CreateView()
{
return (CircularView)Nib.Instantiate(null, null)[0];
}
}
Create another class and name it CircularView.designer.cs
[Register ("CircularView")]
partial class CircularView
{
void ReleaseDesignerOutlets ()
{
}
}
Edit project file and add DependUpon tags like below
BEFORE
<Compile Include="Controls\CircularView.cs" />
<Compile Include="Controls\CircularView.designer.cs" />
AFTER
<Compile Include="Controls\CircularView.cs" />
<Compile Include="Controls\CircularView.designer.cs" >
<DependentUpon>CircularView.cs</DependentUpon>
</Compile>
this will ensure that VS shows the designer file as a child of CircularView.cs
where you want to use the new Custom view do the following
var v = CircularView.CreateView();
vwCustom.Add(v);
where vwCustom is a normal UIView added from Designer in my view controller, you can ofcourse name it anything.
Please let me know if you need further help.

Related

How to load a JavaScript file on all pages programmatically

I have a jsf jar library, and I want to load a specific JavaScript file (exist in the jar) in all pages of the JSF 2.2 project that use it, and without any additional configuration.
I want to load a specific JavaScript file exist in my library without use of
h:outputScript tag in the page( Neither the template nor the page )
Is this possible in jsf web application?
You can use UIViewRoot#addComponentResource() to programmatically add JSF resources. You can use a SystemEventListener on PostAddToViewEvent of <h:head> for this.
public class DynamicHeadResourceListener implements SystemEventListener {
#Override
public boolean isListenerForSource(Object source) {
return "javax.faces.Head".equals(((UIComponent) source).getRendererType());
}
#Override
public void processEvent(SystemEvent event) {
String library = "yourLibraryName";
String name = "yourScript.js"; // Can be dynamic here.
addHeadResource(FacesContext.getCurrentInstance(), library, name);
}
private void addHeadResource(FacesContext context, String library, String name) {
UIComponent resource = new UIOutput();
resource.getAttributes().put("library", library);
resource.getAttributes().put("name", name);
resource.setRendererType(context.getApplication().getResourceHandler().getRendererTypeForResourceName(name));
context.getViewRoot().addComponentResource(context, resource, "head");
}
}
In order to get it to run, register it in faces-config.xml of your module project as below:
<system-event-listener>
<system-event-listener-class>com.example.DynamicHeadResourceListener</system-event-listener-class>
<system-event-class>javax.faces.event.PostAddToViewEvent</system-event-class>
<source-class>javax.faces.component.UIOutput</source-class>
</system-event-listener>

How to add a custom component from encodebegin?

I've created a custom component which extends the UIComponentBase abstract class, so when I use this component: <test:mycomponent /> It works as espected.
I'm creating another custom component and I want to use the previously created component in this one, so I tried:
#Override
public void encodeBegin(FacesContext context) throws IOException {
ResponseWriter writer = context.getResponseWriter();
writer.startElement("mycomponent", this);
writer.endElement("mycomponent");
}
I new this was a long shot, since startElement just creates a tag with the given component name i.e mycomponent, so I searched around and found:
UIComponentBase mycomponent =
(UIComponentBase)context.getApplication().createComponent("mycomponent");
If this is correct, how does one add the component ? I'm using JSF 2.2
A link to where I can find more on this would be greatly apreciated also.

Access static property in JSF

I have a static List of Select Items in one of my backing beans:
private static List<SelectItem> countries = new ArrayList<SelectItem>();
with the following getters and setters:
public static List<SelectItem> getCountries() {
return countries;
}
public static void setCountries(List<SelectItem> countries) {
LoadSelectItemsBean.countries = countries;
}
I am having trouble with accessing the static List through my XHTML page. The code I have tried is as follows:
<ace:simpleSelectOneMenu id="countryField"
value="#{generalCarrierDataViewBean.carrierBean.countryId}">
<f:selectItems value="#{loadSelectItemsBean.countries}" />
<ace:ajax />
</ace:simpleSelectOneMenu>
The problem line is:
<f:selectItems value="#{loadSelectItemsBean.countries}" />
The exception which results is:
javax.el.PropertyNotFoundException: /pages/GeneralCarrierData.xhtml #394,64 value="#{loadSelectItemsBean.states}": Property 'states' not found on type com.oag.reference.util.LoadSelectItemsBean
Can anbody advise on how to correctly reference a static property from a backing bean?
Thanks
Properties are per definition not static. So getters and setters can simply not be static, although they can in turn reference a static variable. But the outside world does not see that.
You've 3 options:
Remove the static modifier from the getter. The whole setter is unnecessary, you can just remove it.
public List<SelectItem> getCountries() {
return countries;
}
Create an EL function if you really insist in accessing static "properties" (functions). Detail can be found in this answer: How to create a custom EL function to invoke a static method?
Turn the whole List<SelectItem> thing into an enum and make use of OmniFaces <o:importConstants>. Detail can be found in this answer: How to create and use a generic bean for enums in f:selectItems?
Just create a non-static method that returns the static property:
// here you have a static String
private static String static_str;
public static String getStatic_str() {
return static_str;
}
// in jsf page: #{myClass.str}
public String getStr() {
return static_str;
}

Equivalent FXML attribute to ChangeListener?

I'm in the process of converting a JavaFX application from declaring/configuring its controls in Java code to splitting out the layout to an FXML config. The problem I'm having is that I can't locate the equivalent attribute (?) to the code's ChangeListener.
In the original Java code, I have
class TextFieldChangeListener implements ChangeListener<String> {
private boolean isRequiredDataPresent() {
return outputNameTextField.getText().length() > 0 && numOfOutputFilesTextField.getText().length() > 0;
}
#Override
public void changed( ObservableValue<? extends String> observableValue, String s, String s2 ) {
mergeButton.setDisable( ! isRequiredDataPresent() );
}
}
About the closest I can get using FXML is:
<TextField id="outputNameTextField" onKeyPressed="#textBoxOnChange" promptText="Path of merge file" GridPane.columnIndex="1" GridPane.rowIndex="3" GridPane.columnSpan="2" GridPane.rowSpan="1" />
The problem with using onKeyPressed is that it doesn't pickup pasted in values like ChangeListener does. How do I add a change listener in FXML?
You can not do that because the value property is a sub-part of TextField. So you have to write it in your code. FXML comes only for the graphical aspects.
For more information about FXML :
http://docs.oracle.com/javafx/2/get_started/fxml_tutorial.htm
http://docs.oracle.com/javafx/2/fxml_get_started/jfxpub-fxml_get_started.htm

How to override CustomerStateRequestProcessor in broadleaf

How can I ovveride CustomerStateRequestProcessor#resolveAuthenticatedCustomer function in broadleaf?
I tried this:-
#Component("blCustomerStateRequestProcessor")
public class MyCustomerStateRequestProcessor extends
CustomerStateRequestProcessor {
#Resource(name = "blCustomerService")
protected CustomerService customerService;
#Override
public Customer resolveAuthenticatedCustomer(Authentication authentication) {
if (authentication instanceof OpenIDAuthenticationToken) {
OpenIDAuthenticationToken openIDAuthenticationToken = (OpenIDAuthenticationToken) authentication;
if (openIDAuthenticationToken.isAuthenticated()) {
return (Customer) openIDAuthenticationToken.getPrincipal();
} else {
return null;
}
} else {
return super.resolveAuthenticatedCustomer(authentication);
}
}
}
Added context component scan :-
<context:component-scan base-package="org.broadleafcommerce.common.web.security,com.mycompany.web.request.processor" />
This resulted in :-
org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'blCustomerStateRequestProcessor' for bean class [org.broadleafcommerce.profile.web.core.security.CustomerStateRequestProcessor] conflicts with existing, non-compatible bean definition of same name and class [com.mycompany.web.request.processor.MyCustomerStateRequestProcessor]
I am trying to overrid resolveAuthenticatedCustomer method for OpenIdAuthenticationToken.
Thanks
Rather than use component-scanning to redefine the bean, remove that annotation and do it via XML instead.
So your class definition would change to:
public class MyCustomerStateRequestProcessor extends
CustomerStateRequestProcessor {
...
}
And then in any of your applicationContext.xml files (except for the servlet one) add this:
<bean id="blCustomerStateRequestProcessor" class="com.yourcompany.site.web.MyCustomerStateRequestProcessor" />
Note that this pattern is the same for overriding any Broadleaf-defined beans.

Resources